<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ include file="../../commons/import_taglibs.jsp" %>
<div class="panel panel-default">
    <div class="panel-heading"><b>${project.id == null ? '新增项目' : '编辑项目'}</b></div>
    <div class="panel-body">
        <div class="row">
            <div class="col-lg-12">
                <form id="projectForm" class="form-horizontal" action="/deploy/project/save" method="post">
                    <input type="hidden" name="id" value="${project.id}"/>

                    <div class="form-group">
                        <label class="col-lg-2 control-label">项目名称</label>
                        <div class="col-lg-9">
                            <input type="text" class="form-control" name="name" value="${project.name}"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-2 control-label">项目路径</label>
                        <div class="col-lg-9">
                            <input type="text" class="form-control" name="path" value="${project.path}"/>
                            <p class="help-block">项目所在服务器路径。例如：/data/xxtweb </p>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-2 control-label">启用</label>
                        <div class="col-lg-9">
                            <select class="form-control" name="inUse">
                                <option value="1" ${project.inUse ? "selected" : ""}>是</option>
                                <option value="0" ${!project.inUse ? "selected" : ""}>否</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-2 control-label">备注</label>
                        <div class="col-lg-9">
                            <textarea class="form-control" name="desc" rows="10"
                                      placeholder="请输入...">${project.desc}</textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-2 control-label">排序</label>
                        <div class="col-lg-9">
                            <input type="number" class="form-control" name="sort" value="${project.sort}"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-lg-9 col-lg-offset-2">
                            <button type="submit" class="btn btn-primary">保存</button>
                            <button type="reset" class="btn btn-default">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!-- /.row (nested) -->
    </div>
    <!-- /.panel-body -->
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#projectForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                inUse: {
                    message: 'The value is not valid',
                    validators: {
                        notEmpty: {
                            message: '必填项不能为空！'
                        }
                    }
                },
                name: {
                    message: 'The value is not valid',
                    validators: {
                        notEmpty: {
                            message: '必填项不能为空！'
                        }
                    }
                },
                path: {
                    message: 'The value is not valid',
                    validators: {
                        notEmpty: {
                            message: '必填项不能为空！'
                        },
                        remote: {
                            url: '/deploy/project/checkPath',
                            message: '验证失败！请按照要求检查输入：必须为绝对路径，且存在的文件夹！'
                        }
                    }
                },
                sort: {
                    message: 'The value is not valid',
                    validators: {
                        integer: {
                            message: '只能是数字！'
                        }
                    }
                }
            }
        }).on('success.form.bv', function (e) {
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            $.post($form.attr('action'), $form.serialize(), function (result) {
                layer.msg(result.message, {
                    shade: [0.3, '#000'],
                    icon: (result.success ? 1 : 2)
                }, function () {
                    if (result.success) {
                        $('#page-wrapper').load('/deploy/project/list');
                    }
                });
            }, 'json');
        });
    });
</script>